{include file='public/head'}
<body>
<style type="text/css" media="screen">
    header {
        color: black;
    }

    .layui-table {
        margin: 0 0;
    }

    #weight {
        width: 80px;
        display: initial;
    }

    .x-body {
        min-width: 700px;
    }

    body {
        overflow-x: scroll;
    }
</style>


<div class="x-body">
    <form class="layui-form" id='mainForm' method="post" action="waybillAdd">
        <input type="hidden" name="order_id" id="order_id" value="{$Think.get.order_id}">
        <input type="hidden" name="company_id" id="company_id" value="{$Think.get.company_id}">
        <table class="layui-table">
            <thead>
            <tr>
                <th style="width: 75px;text-align:center"></th>
                <th style="width: 75px;text-align:center">商品数量</th>
                <th style="width: 75px;text-align:center">商品图片</th>
                <th>商品名称</th>
            </thead>
            <tbody>

            {volist name="orderGoods" id="vo"}
            <tr>
                {if $vo.good_status eq 7}
                <td style="text-align:center">
                    <input type="checkbox" name="sku[]" value="{$vo.order_item_id}" lay-skin="primary" checked>
                </td>
                <td>
                    <input type="number" id="num[]" name="num[{$vo.order_item_id}]" class="layui-input" min="0"
                           value="{$vo.num}" max="{$vo.num}">
                </td>
                {else/}
                <td style="text-align: center">{$vo.num}</td>
                {/if}
                <td style="text-align: center">
                    {if empty($vo['url'])}
                    <img src="__images__/noimg.png">
                    {else/}
                    <img src="{$vo['url']}" onclick="previewImg(this)">
                    {/if}
                </td>
                <td>{$vo.goods_name}</td>
                <input type="hidden" name="title[{$vo.order_item_id}]" value="{$vo.goods_name}">
                <input type="hidden" name="lang[{$vo.order_item_id}]" value="{$vo.lang}">
                <input type="hidden" name="guid[{$vo.order_item_id}]" value="{$vo.guid}">
                <input type="hidden" name="url[{$vo.order_item_id}]" value="{$vo.url}">
            </tr>
            {/volist}
            </tbody>
        </table>
        <table class="layui-table">
            <colgroup>
                <col width="120">
                <col width="150">
                <col width="150">
                <col width="120">
                <col width="150">
                <col width="150">
            </colgroup>
            <tbody>
            <tr>
                <td><span style="color: red">*</span>物流公司</td>
                <td colspan="2">
                    <select name="logistic_id" id='logistic_id' lay-verify="required" lay-filter="logistic_id">
                        <option value="">请选择</option>
                        {volist name="logistics" id="vo"}
                        <option value="{$vo.id}" title="{$vo.manual}">{$vo.name}</option>
                        {/volist}
                    </select>
                </td>
                <td><span style="color: red">*</span>货运方式</td>
                <td colspan="2">
                    <select name="shipping_method" id='shipping_method' lay-verify="required"
                            lay-filter="shipping_method">
                        <option value="">请选择</option>
                    </select>
                    <input type="hidden" id="logistic" name="logistic" value="">
                </td>
            </tr>
            <tr>
                <td><span style="color: red">*</span>海关简称（英文）</td>
                <td colspan="2">
                    <input type="text" id="customs_en" name="customs_en" class="layui-input" placeholder="请输入简要英文描述"
                           lay-verify="required">
                </td>
                <td>海关简称（中文）</td>
                <td colspan="2">
                    <input type="text" id="customs" name="customs" class="layui-input" placeholder="请输入简要中文描述">
                </td>
            </tr>
            <tr>
                <td>面单</td>
                <td colspan="2">
                    <input type="text" id="express" name="express" class="layui-input" placeholder="请输入物流面单号码">
                </td>
                <td>海关</td>
                <td colspan="2">
                    <input type="text" id="coding" name="coding" class="layui-input" placeholder="请输入海关编码">
                </td>
            </tr>
            <tr>
                <td>追踪</td>
                <td colspan="2">
                    <input type="text" id="waybill" name="waybill" class="layui-input" placeholder="请输入运单追踪号">
                </td>
                <td>发货</td>
                <td colspan="2">
                    <input type="text" id="deliver" name="deliver" class="layui-input" placeholder="请选择发货日期" value="">
                </td>
            </tr>
            <tr>
                <td><span style="color: red">*</span>申报</td>
                <td>
                    <select name="declare_unit_id" id='declare_unit_id' lay-verify="required"
                            lay-filter="declare_unit_id">
                        {volist name="unit" id="vo"}
                        <option value="{$vo.id}" title="{$vo.sign}" {if $vo['sign'] eq 'USD'} selected {/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                    <input type="hidden" id="declare_unit" name="declare_unit" value="USD">
                </td>
                <td>
                    <input type="text" id="declare" name="declare" class="layui-input" lay-verify="required">
                </td>
                <td><span style="color: red">*</span>总重</td>
                <td>
                    <input type="text" id="weight" name="weight" class="layui-input" value="" lay-verify="required"> 克
                </td>
                <td>
                    <input type="checkbox" name="is_battery" title="有电池" value="2" lay-skin="primary">
                </td>
            </tr>
            <tr>
                <td>保险</td>
                <td>
                    <select name="insure_unit_id" id='insure_unit_id' lay-verify="required" lay-filter="insure_unit_id">
                        {volist name="unit" id="vo"}
                        <option value="{$vo.id}" title="{$vo.sign}">{$vo.name}</option>
                        {/volist}
                    </select>
                    <input type="hidden" id="insure_unit" name="insure_unit" value="{$unit[0]['sign']}">
                </td>
                <td>
                    <input type="text" id="insure" name="insure" class="layui-input">
                </td>
                <td>运费</td>
                <td>
                    <select name="fee_unit_id" id='fee_unit_id' lay-verify="required" lay-filter="fee_unit_id">
                        {volist name="unit" id="vo"}
                        <option value="{$vo.id}" title="{$vo.sign}">{$vo.name}</option>
                        {/volist}
                    </select>
                    <input type="hidden" id="fee_unit" name="fee_unit" value="{$unit[0]['sign']}">
                </td>
                <td>
                    <input type="text" id="fee" name="fee" class="layui-input" value="0">
                </td>
            </tr>
            <tr>
                <td>备注</td>
                <td colspan="5">
                    <textarea id="remark" name="remark" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </tr>
            </tbody>
        </table>

        <div class="layui-form-item" style="margin-top: 15px">
            <div>
                <button style="width: 100%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交保存</button>
            </div>
        </div>
    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">

    $(document).ready(function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#deliver' //指定元素
        });

        form.on('select(logistic_id)', function (data) {
            layer.load(1);
            $("#shipping_method").html("");
            var manual = data.elem[data.elem.selectedIndex].title;
            $.ajax({
                url: "getLogisticShip.html",
                async: true,
                dataType: 'json',
                data: {logistics_id: data.value, manual: manual,order_id:$("#order_id").val()},
                type: "post",
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.status == false) {
                        layer.alert(res.msg);
                    } else {
                        var data = res.data;
                        var html = '<option value="">请选择</option>';
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value=" + data[i].method_code + ">" + data[i].cn_name + "</option>";
                        }
                        $("#shipping_method").append(html);
                        form.render('select');
                    }
                }
            })
        });

        form.on('select(shipping_method)', function (data) {
            $("#logistic").val(data.elem[data.elem.selectedIndex].text);
        });

        form.on('select(declare_unit_id)', function (data) {
            $("#declare_unit").val(data.elem[data.elem.selectedIndex].title);
        });

        form.on('select(insure_unit_id)', function (data) {
            $("#insure_unit").val(data.elem[data.elem.selectedIndex].title);
        });

        form.on('select(fee_unit_id)', function (data) {
            $("#fee_unit").val(data.elem[data.elem.selectedIndex].title);
        });
        var options = {
            type: 'post',           //post提交
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.alert(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };

        // bind form using 'ajaxForm'
        $('#mainForm').ajaxForm(options).submit(function (data) {});
        form.render();
    });
</script>
</html>
